package com.fhz.kotlin1904a

import java.util.function.Consumer

/**
 * 时间:2021/10/12
 * @author msfeng
 */
fun main(){
    println("哈哈哈")

    val s = "abc"

    println("s 的长度 ${s.length}")

    val add1 = add(1, 2)
    println("add $add1")

    val describe = describe("123123")
    println(describe)


    val mutableListOf1 = mutableListOf<Any>()
    mutableListOf1.add("123")
    mutableListOf1.add(123)


    mutableListOf1.forEach(Consumer {
        when (it) {
            is String -> println("123")
            is Int -> {
                println(123)
                val d = it * 10.0
                println(d)
                mutableListOf1.add(d)
            }
        }
    })






//    val items = listOf("apple", "banana", "kiwifruit") //数组
//    val mutableListOf = mutableListOf("apple", "banana", "kiwifruit") //list
//    for (i in mutableListOf){
//        println(i)
//    }
//
//    for (i in 10 downTo 0 step 2){
//        println(i)
//    }
//
//    for (i in 10 downTo 0 step 2){
//        println(i)
//    }

}

//普通写法
fun add(a:Int, b:Int):Int{
    return a + b
}

fun describe(obj: Any): String =
    when (obj) {
        is Int -> "int"
        "Hello"    -> "Greeting"
        is Long    -> "Long"
        !is String -> "Not a string"
        else       -> "Unknown"
}



fun add1(a:Int, b:Int) = a + b

fun maxOf(a: Int, b: Int) = if (a > b) a else b

